import java.util.Scanner;
/**
 * 吃货联盟订餐系统
 */
public class ChiHuoLianMeng {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        //数据主体
        String[] shiPing={"红烧排骨","青椒肉丝","小鸡炖蘑菇"};
        double[] money={18.0,38.0,20};
        int[] dinZanShu=new int[3];
        double sum=0; //总餐费
        //数据主体
        String[] person=new String[4];  //订单人
        String[] canPing=new String[4]; //餐品信息
        int[]time=new int[4];           //送餐时间
        String[] diZhi = new String[4];    //送餐地址
        int[] dinDanZT=new int[4];    //定单状态  0 ：已预定  1：已完成
        double[] prices = new double[4];     //总价格
        //初始化两条订单
        person[0]="李爽";
        canPing[0]="红烧排骨";
        time[0]=12;
        diZhi[0]="聚友公寓";
        dinDanZT[0]=0;
        prices[0]=24.0;     //一份18元总金额未达到50 另加五元送餐费
        person[1]="李爽";
        canPing[1]="青椒肉丝2份";
        time[1]=13;
        diZhi[1]="时瑞大厦";
        dinDanZT[1]=0;
        prices[1]=76.0;    //一份38元 两份达到50元不需要另加5元送餐费
        System.out.println("欢迎使用吃货联盟订餐系统");
        do {
            System.out.println("*******************************");
            System.out.println("1.我要订餐");
            System.out.println("2.查看餐袋");
            System.out.println("3.签收订单");
            System.out.println("4.删除订单");
            System.out.println("5.我要点赞");
            System.out.println("6.退出系统");
            System.out.println("*******************************");
            System.out.println("请选择：");
            int num = input.nextInt();
            if (num>=6){
                System.out.println("欢迎下次使用吃货联盟系统");
                break;
            }
            boolean flag = false;
            switch (num){
                case 1:
                    System.out.println("*******我要订餐*******");
                    for (int i =0;i<person.length;i++){         //寻找空位置
                        if (person[i]==null){
                            flag=true;          //记录一下已经找到一个为空的位置
                            //显示餐品信息
                            System.out.println("序号\t餐品名\t\t单价\t点赞数");
                            for (int j = 0; j <person.length-1 ; j++) {
                                System.out.println((j+1)+"\t\t"+shiPing[j]+"\t"+money[j]+"元\t"+dinZanShu[j]+"点赞");
                            }
                            //输入提示信息
                            System.out.print("请输入您要点的食物：");
                            int num1=input.nextInt();
                            System.out.print("请输入您要点的份数：");
                            int num2 = input.nextInt();
                            System.out.print("请输入您的姓名：");
                            String name=input.next();
                            System.out.print("请输入您的地址：");
                            String dizhi=input.next();
                            System.out.print("请输入送餐时间(8:00-18:00)");
                            int shijian = input.nextInt();
                            while (shijian>18||shijian<8){
                                System.out.println("您输入的有误，请重新输入");
                                shijian = input.nextInt();
                            }
                            //计算餐费
                            int canfei;
                            sum=money[num1-1]*num2;
                            if (sum>50){
                                canfei=0;
                            }else {
                                canfei=5;
                            }
                            //显示订单信息
                            System.out.println("订餐成功");
                            System.out.println("您订的食物为"+shiPing[num-1]+"，订了"+num2+"份");
                            System.out.println("订餐人:"+name);
                            System.out.println("订餐地址:"+dizhi);
                            System.out.println("送餐时间:"+shijian+":00");
                            System.out.println("餐费:"+sum+"\t送餐费:"+canfei);
                            System.out.println("总金额为:"+(sum+canfei));
                            //保存数据
                            person[i]=name;
                            canPing[i]=shiPing[num-1]+num2;
                            time[i]=shijian;
                            diZhi[i]=dizhi;
                            prices[i]=sum+canfei;
                            break;
                        }
                    }
                    if (!flag){
                        System.out.println("对不起，订餐人已满");
                    }
                    break;
                case 2:
                    System.out.println("*******查看餐袋*******");
                    System.out.println("序号\t订餐人\t\t\t所定餐品信息  \t送餐时间\t送餐地址\t总金额\t状态");
                    for (int i = 0; i <person.length ; i++) {
                        int zhuangtai=dinDanZT[i];
                        if (zhuangtai==0){
                            if (person[i]!=null){
                                System.out.println((i+1)+"\t\t"+person[i]+"\t\t\t"+canPing[i]+"\t\t"+time[i]+"\t\t\t"+diZhi[i]+"\t"+money[i]+"\t"+"已预定");
                            }
                        }else{
                            if (person[i]!=null){
                                System.out.println((i+1)+"\t\t"+person[i]+"\t\t"+canPing[i]+"\t\t"+time[i]+"\t\t\t"+diZhi[i]+"\t"+money[i]+"\t"+"已完成");
                            }
                        }

                    }
                    break;
                case 3:
                    System.out.println("*******签收订单*******");
                    System.out.println("请输入要签收的订单序号");
                    int num3=input.nextInt();
                    boolean flag1=false;
                    for (int i = 0; i <person.length ; i++) {
                        if (person[i]!=null&&dinDanZT[i]==1&&num3==i+1){
                            System.out.println("对不起你选择的订单已完成，不可签收");
                            flag=true;
                            break;
                        }else if(person[i]!=null&&dinDanZT[i]==0&&num3==i+1){
                            System.out.println("签收成功");
                            dinDanZT[i]=1;
                            flag=true;
                            break;
                        }
                    }
                    if (!flag){
                        System.out.println("对不起，此订单不存在");
                    }

                    break;
                 case 4:
                    System.out.println("*******删除订单*******");
                     System.out.println("请输入你要删除的订单：");
                     int num4=input.nextInt();
                    boolean shanchu=false;
                     for (int i = 0; i <person.length ; i++) {
                         if (person[i]!=null&&dinDanZT[i]==1&&num4==i+1){
                             for (int j = num4-1; j <person.length-1 ; j++) {
                                 person[j]=person[j+1];
                                 canPing[j]=canPing[j+1];
                                 time[j]=time[j+1];
                                 diZhi[j]=diZhi[j+1];
                                 dinDanZT[j]=dinDanZT[j+1];
                             }
                             person[person.length-1]=null;
                             canPing[person.length-1]=null;
                             time[prices.length-1]=0;
                             diZhi[person.length-1]=null;
                             dinDanZT[person.length-1]=0;
                             shanchu=true;
                             System.out.println("已删除");
                             break;
                             }else if (person[i]!=null&&dinDanZT[i]==0&&num4==i+1){
                             System.out.println("订单未签收 无法删除");
                             shanchu=true;
                             break;
                            }
                         }
                     if (!shanchu){
                         System.out.println("没找到订单，无法删除");
                         break;
                     }
                    break;
                case 5:
                    System.out.println("*******我要点赞*******");
                    System.out.println("序号\t菜品名\t\t单价");
                    for (int i = 0; i <person.length-1 ; i++) {
                        if (dinZanShu[i]>0){
                            System.out.println((i+1)+"\t\t"+shiPing[i]+"\t\t"+money[i]+"\t\t"+dinZanShu[i]+"赞");
                        }else {
                            System.out.println((i+1)+"\t\t"+shiPing[i]+"\t\t"+money[i]);
                        }
                    }
                    System.out.println("请输入你要点赞的序号");
                    int num5=input.nextInt();
                    switch (num5){
                        case 1:
                            dinZanShu[0]++;
                            break;
                        case 2:
                            dinZanShu[1]++;
                            break;
                        case 3:
                            dinZanShu[2]++;
                            break;
                        default:
                            System.out.println("输入错误请重新输入");
                            num5=input.nextInt();
                    }
                    System.out.println("点赞成功");
                    break;
            }
            System.out.print("输入0返回");
            num = input.nextInt();
            if (num!=0){
                System.out.println("欢迎下次使用吃货联盟系统");
                break;
            }
        }while (true);
    }
}
